package com.datang.petstore.exception;


import com.datang.petstore.resultpage.Result;
import com.datang.petstore.resultpage.ResultCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


/*
 * @auther 顶风少年
 * @mail dfsn19970313@foxmail.com
 * @date 2019-05-09 19:55
 * @notify controller层统一异常处理
 * @version 1.0
 */
@ControllerAdvice
@ResponseBody
public class GlobalExceptionHandler {
    private static final Logger LOG = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    /*
     * @author 顶风少年
     * @date 2019/5/9 23:24
     * @mail dfsn199703132038@foxmail.com
     * @throws
     * @param
     * @param code 状态码
     * @param message 返回说明
     * @param data 返回数据
     * @result
     * @notify
     * version 1.0
     */
    @ExceptionHandler(AcceptResultCodeException.class)
    Result handleException(AcceptResultCodeException e) {

        ResultCode resultCode = e.getResultCode();

        LOG.error(resultCode.getCode() + resultCode.getMessage(), e);

        return Result.err(e.getResultCode());
    }
}
